package server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server implements RPCServer{
    private ServiceProvider serviceProvider;
    public Server(ServiceProvider serviceProvider){
        this.serviceProvider = serviceProvider;
    }
    @Override
    public void start(int port) {
        try {
            ServerSocket serverSocket = new ServerSocket(port);
            System.out.println("服务器已启动=====>");
            while (true){
                Socket socket = serverSocket.accept();
                new Thread(new WorkThread(socket, serviceProvider)).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("服务器启动失败=====>");
        }
    }

    @Override
    public void stop() {

    }
}
